<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form" action="" id="formId">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">头像</label>
                    <div class="layui-input-block" >
                        <div onclick="uploadImg(this)" style="float: left;">
                        <img  src="/static/efile/auserimg/{$msg.img|default='default.jpg'}" id="headImgId" class="layui-nav-img" style="border: solid #000 1px;cursor: pointer;">
                        </div>
                    </div>
                    <input type="file" name="img" style="display:none;" id="fileId">
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" value="{$msg.username|default=''}" lay-verify="title" autocomplete="off"
                            placeholder="请输入账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" value="{$msg.password|default=''}" lay-verify="title" autocomplete="off" placeholder="请输入密码"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="nickname" value="{$msg.nickname|default=''}" lay-verify="title" autocomplete="off"
                            placeholder="请输入昵称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="reaname" value="{$msg.reaname|default=''}" lay-verify="title" autocomplete="off" placeholder="请输入姓名"
                            class="layui-input">
                    </div>
                </div>
                
                
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" value="{$msg.mobile|default=''}" lay-verify="title" autocomplete="off"
                            placeholder="请输入电话" class="layui-input">
                    </div>
                </div>
                {if !$Request.get.t}
                <div class="layui-form-item">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <select name="role_id" lay-verify="title">
                            <option value="0">请选择一个角色</option>
                            {php}$role_id=empty($msg) ? 0 : $msg['role_id']; {/php}
                            {volist name="lst" id="vo"}
                            <option value="{$vo.id}" {if $role_id == $vo.id} selected {/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                {/if}
                {if !$Request.get.t}
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        {php} 
                            $status=[
                                0=> empty($msg['status']) ? "checked" : "",
                                1=> empty($msg['status']) ? "" : "checked",
                            ];
                        {/php}
                        <input type="radio" name="status" value="0" title="开启" {$status[0]}>
                        <input type="radio" name="status" value="1" title="冻结" {$status[1]}>
                    </div>
                </div>
                {/if}
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
        <script src="/static/user/js/jquery.min.js"></script>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script>
         
            function uploadImg(item) {
                $("#fileId").click();
            }
            $("#fileId").change(function () {
                if ($(this).val()) {
                    var imgurl = getObjectURL(this.files[0]);
                    $("#headImgId").attr("src", imgurl);
                }
            });
          function getObjectURL(file) {
                var url = null;
                if (window.createObjectURL != undefined) { // basic
                    url = window.createObjectURL(file);
                } else if (window.URL != undefined) { // mozilla(firefox)
                    url = window.URL.createObjectURL(file);
                } else if (window.webkitURL != undefined) { // webkit or chrome
                    url = window.webkitURL.createObjectURL(file);
                }
                return url;
            }


        layui.use(['form', 'jquery'], function () {
            let form = layui.form;
            let $ = layui.jquery;
            
            form.on('submit(form-save)', function (data) {
                //var data = data.field ;//JSON.stringify(data.field);
                var data = $("#formId");
                '{if !$Request.get.t}'
                       var url="{:url('admin/auserSave')}?id={$Request.get.id}";
                '{else/}'
                    var url="{:url('admin/auserSave')}?id={$Request.session.lt_auser.id}&t=1";
                '{/if}'
                postDatai(url,data).then(function(res){
                    if (res.code==200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                               '{if !$Request.get.t}'
                                    parent.layui.table.reload("tableId");
                                '{/if}'
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });
        })
    </script>
    {include file="base/unitjs"}
</body>

</html>